﻿using CommonServiceLocator;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using WebFirst.Entities;

namespace Jn698._45GWTool.ViewModels
{
    public class PowerCtrlParamViewModel:ViewModelBase
    {
        public static GWCmdMakeUp GWCmdMakeUp;
        private string number;

		public string Number
		{
			get { return number; }
			set { number = value; RaisePropertyChanged(); }
		}

		private string value1;

		public string Value1
		{
			get { return value1; }
			set { value1 = value; RaisePropertyChanged(); }
		}

        private string value2;

        public string Value2
        {
            get { return value2; }
            set { value2 = value; RaisePropertyChanged(); }
        }
        private string value3;

        public string Value3
        {
            get { return value3; }
            set { value3 = value; RaisePropertyChanged(); }
        }

        private string value4;

        public string Value4
        {
            get { return value4; }
            set { value4 = value; RaisePropertyChanged(); }
        }
        private string value5;

        public string Value5
        {
            get { return value5; }
            set { value5 = value; RaisePropertyChanged(); }
        }
        private string value6;

        public string Value6
        {
            get { return value6; }
            set { value6 = value; RaisePropertyChanged(); }
        }
        private string value7;

        public string Value7
        {
            get { return value7; }
            set { value7 = value; RaisePropertyChanged(); }
        }
        
        private string value8;

        public string Value8
        {
            get { return value8; }
            set { value8 = value; RaisePropertyChanged(); }
        }

        public PowerCtrlParamViewModel()
        {
            GWCmdMakeUp = ServiceLocator.Current.GetInstance<GWCmdMakeUp>();
            if (GWCmdMakeUp.SubItemName == null)
            {
                return;
            }
            var strings = GWCmdMakeUp.DataValue.Split(',');
            Number = strings[0];
            Value1 = strings[1];
            Value2 = strings[2];
            Value3 = strings[3];
            Value4 = strings[4];
            Value5 = strings[5];
            Value6 = strings[6];
            Value7 = strings[7];
            Value8 = strings[8];
        }

        public RelayCommand<Window> OKCommand
        {
            get
            {
                var command = new RelayCommand<Window>((w) =>
                {
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.Append(int.Parse(Number).ToString("X2"));
                    stringBuilder.Append(',');
                    stringBuilder.Append(value1);
                    stringBuilder.Append(",");
                    stringBuilder.Append(value2);
                    stringBuilder.Append(",");
                    stringBuilder.Append(value3);
                    stringBuilder.Append(",");
                    stringBuilder.Append(value4);
                    stringBuilder.Append(",");
                    stringBuilder.Append(value5);
                    stringBuilder.Append(",");
                    stringBuilder.Append(value6);
                    stringBuilder.Append(",");
                    stringBuilder.Append(value7);
                    stringBuilder.Append(",");
                    stringBuilder.Append(value8);
                    GWCmdMakeUp.DataValue=stringBuilder.ToString();
                    w.DialogResult = true;
                });
                return command;
            }
        }

        public RelayCommand<Window> CancelCommand
        {
            get
            {
                var command = new RelayCommand<Window>((w) =>
                {
                    w.DialogResult = false;
                });
                return command;
            }
        }
    }
}
